import {messages} from "share/common";
import React, { Component } from "react"
import {Input, message, Modal} from 'antd'
import { openModal, removeContainer } from "components/method/openModal";

const { TextArea } = Input;

class FeedbackModal extends Component {

  state = {
    confirmReason: ''
  };

  render() {
    const { visible, onCancel, onOk, afterClose } = this.props;
    const { confirmReason } = this.state;
    return (
      <Modal
        title={messages('expense-16.key327')/*反馈内容*/}
        visible={visible}
        onCancel={onCancel}
        onOk={() => onOk(confirmReason)}
        afterClose={afterClose}
      >
        <TextArea
          rows={3}
          placeholder={messages('expense-16.key78')/*请输入temp2*/}
          maxLength={200}
          style={{ resize: 'none' }}
          onChange={e => this.setState({ confirmReason: e.target.value })}
        />
      </Modal>
    )
  }

}

FeedbackModal.open = function(env) {
  let container;
  let targetProps;
  return new Promise((resolve, reject) => {
    targetProps = {
      visible: true,
      onOk: data => close(data),
      onCancel: () => close(null),
      afterClose: () => {
        removeContainer(container);
        container = null;
      }
    };
    function close(data) {
      if(data === null || (data && data.length)) {
        resolve(data);
        openModal(FeedbackModal, {
          ...targetProps,
          visible: false
        }, env, container)
      }
      else reject();
    }
    container = openModal(FeedbackModal, targetProps, env);
  })
};

export default FeedbackModal
